<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>字典管理</title>
<block th:replace="commonBase"></block>   
</head>   
<body>
     <!-- 菜单栏开始 -->
     <div style="width:100%;">
		<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
			<table style="width:100%;"> 
				<tr>
	                 <td width="35%"> 
	                  	<a class="mini-button"  plain="true"  iconCls="fa fa-plus" onclick="add">添加</a>
	                 	<a class="mini-button"  plain="true"  iconCls="fa fa-edit"   onclick="edit">编辑</a>
	                 	<a class="mini-button"  plain="true"  iconCls="fa fa-remove" onclick="remove">删除</a> 
	                 	<a class="mini-button"  plain="true"  iconCls="fa fa-upload" onclick='importData'>导入</a> 
	                  	<a   class="mini-button"  plain="true"  iconCls="icon-redo" target="_self" th:href="@{/tempxls/sjzd.xlsx}" >下载模板</a> 
	                  </td>	
					 <td align="right">
						<input id="searchKey" class="mini-textbox" emptyText="请输入名称或编码" style="width:150px;" onenter="search"/>
						<a class="mini-button" plain="true" onclick="search()" iconCls="icon-search">查询</a>
					 </td>    
				</tr>
			</table>
		</div>
	</div>
	<!-- 菜单栏结束 -->
    
    <!-- 列表展示开始 -->   
	<div class="mini-fit">
		<div id="grid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="20" pageList="[10,20,50,100]"  
			 allowCellSelect="true" multiSelect="true" allowAlternating="false" sortField="CREATE_TIME" sortOrder="desc" idField="id"   
			 th:attr="url=@{/dict/pagelist}"  >
			<div property="columns">
				<div type="checkcolumn"></div>
				<div field="itemName"  sortField="ITEM_NAME" headerAlign="center" align="left" width="100" allowSort="true">字典项名称</div>
				<div field="itemCode"  sortField="ITEM_CODE" headerAlign="center" align="left" width="130" allowSort="true">字典项编码</div>
				<div field="dictCode" sortField="DICT_CODE"  headerAlign="center" align="left" width="80" allowSort="true">字典内容</div>
				<div field="dictValue"  width="80"  headerAlign="center" align="left" >字典值</div>  
				<div field="isEnabled" width="80"  renderer="onOpenURenderer" headerAlign="center" align="center" >是否启用</div>
				<div field="sort" allowSort="true"  width="80" headerAlign="center" align="right">排序字段</div>   
				<div field="createUserId" sortField="CREATE_USER_ID" width="100" allowSort="true" headerAlign="center" align="left">创建人</div>
				<div field="createTime" width="150" dataType="date" sortField="CREATE_TIME" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer" headerAlign="center" align="center" allowSort="true">创建时间</div>
				<div field="updateUserId" sortField="UPDATE_USER_ID" width="100" allowSort="true" headerAlign="center" align="left">更新人</div>  
				<div field="updateTime" width="150" dataType="date" sortField="UPDATE_TIME" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer" allowSort="true" headerAlign="center" align="center">更新时间</div>
				<div field="remark" width="120" headerAlign="center" align="left" >备注</div>	
			</div>
		</div>
	</div>
	<!-- 列表展示结束 -->  
</body>

<script th:inline="javascript" type="text/javascript">
 /*<![CDATA[*/
	var grid =  null;//表格对象
	$(function(){
		  mini.parse();
		  grid = mini.get("grid1");
		  search();
	});
	
	/***查询***/
	function search() {
		var  searchKey= mini.get("searchKey").getValue();
		if(searchKey!=""){
			grid.load({"searchPhrase":searchKey});
		}else{
			grid.load();
		}
	}
	
	function add(){
		 mini.open({
	        url:basePath+"dict/edit",
	        title: "新增数据字典", width: 600, height: 350,
	        onload: function () {
	            var iframe = this.getIFrameEl();
	            var data = { action:"new"};
	            iframe.contentWindow.setData(data);
	        },
	        ondestroy: function (action) {
				if (action != "close" && action != "cancle"){
	        		  search();
				}
	        }
	    });
	}
	
	function edit(){
		var rows = grid.getSelecteds();
		if(rows.length>1){
			mini.alert("只能选择一条记录!");
			return;
		}
		var row = grid.getSelected();
	    if (row) {
				 mini.open({
			        url:basePath+"dict/edit",
			        title: "编辑数据字典", width: 528, height: 360,
			        onload: function () {
			             var iframe = this.getIFrameEl();
			            var data = {action:"edit",fwPlDict:row};
			            iframe.contentWindow.setData(data);
			        },
			        ondestroy: function (action) {
						if (action != "close" && action != "cancle"){
			        		  search();
						}
			        }
			    });
	    }
	
	}
	
	// 删除
	function remove(){
		var rows = grid.getSelecteds();
		if (rows.length > 0 ){
			mini.confirm("确定删除选中记录？","提示!",function(e){
				if (e == "ok"){
					var rowArray = [];// 当前删除行的数组
					var rowIndex = 0;
				    if (rows.length > 0) {
				        // 当前选中列数据循环检测
				  		$.each(rows,function (idx,rowsObj){
				  			var nid = rowsObj.id;
							rowArray[rowIndex++] = nid;
				  		});
				       if (rowArray.length != 0){
				       		var ids = rowArray.toString();
				       		 $.ajax({
				       			url:basePath+"dict/delete?ids="+ids,
				       			type:"delete",
				       			data:null,
				       			success:function(successData){
				       	        	var message = mini.decode(successData);
						        	if(message.type == '200'){
						            	showMsg("数据字典删除成功","success",800,"center","center");
						        	    search();
						        	    var storage=window.localStorage;
						            	storage.removeItem("dictData");
						            	$.ajax({  
						    	            type: "get",  
						    	            dataType: "json",  
						    	            url: basePath+"dict/list",  
						    	            data:null,  
						    	            success: function (data) {  
						    	            	var dictData=JSON.stringify(data);
						    	                 storage.setItem("dictData",dictData);
						    	            } 
						    	        });  
						        	}else{
						        		showMsg("数据字典删除失败","warning",800,"center","center");
						        	}
				       			},
				       			error:function(errorData){
		        	 				showMsg("数据字典删除错误","danger",800,"center","center");
				       			}
				       		}); 
				       }
				    }
				}
			});
		}else{
			mini.alert("请选中一条记录!");
		}
	}
	
	var openU = [{ id: 1, text: '是' }, { id: 0, text: '否'}];
	function onOpenURenderer(e) {
	    for (var i = 0, l = openU.length; i < l; i++) {
	        var g = openU[i];
	        if (g.id == e.value) return g.text;
	    }
	    return "";
	}
	
	function ondayRenderer(e){
		//alert();
		
			var operateDate = e.value;
	       	if(!operateDate){
	       		return "";
	       	}
	        return format(operateDate, 'yyyy-MM-dd HH:mm:ss');
	}
	
// 	function onrenderValue(e){
// 		return getDict(e.row.itemCode,e.value);
// 	}
	
	
	function importData(){
	  	mini.open({
		        url:basePath+"dict/upload",
		        title: "文件上传", width: 1024, height: 400,
		        showMaxButton: true,  
		        onload: function () {
		            var iframe = this.getIFrameEl();
		            var data = { action:"edit"};
		            iframe.contentWindow.setData(data);
		        },
		        ondestroy: function (action) {
		        	grid.reload();
		        }
		    });
	  }

/*]]>*/
</script>
</html>